<template>
  <div class="person">
    <h3>我是Person组件，下面一共有{{imgList.length}}图片</h3>
    <input type="text" v-model="name" placeholder="名字">
    <input type="text" v-model.number="age" placeholder="年龄">
    <button @click="handleAddPerson">添加</button>
    <ul>
      <li v-for="p in personList" :key="p.id">
        {{p.name}} -- {{p.age}}
      </li>
    </ul>
  </div>
</template>

<script>
  import { mapState } from 'vuex'
  import {v4} from 'uuid'

  export default {
    name:'Person',
    data() {
      return {
        name:'',
        age:''
      }
    },
    methods: {
      handleAddPerson(){
        const obj = {id:v4(),name:this.name,age:this.age}
        console.log(obj)
        this.$store.dispatch('addPerson',obj)
      }
    },
    computed:{
      ...mapState(['personList','imgList'])
    }
  }
</script>

<style scoped>
  .person {
    background-color: orange;
    padding: 10px;
    box-shadow: 0 0 10px;
    border-radius: 10px;
  }
  input {
    width: 100px;
    margin-right: 10px;
  }
</style>